import type {IColumnsOption} from 'vc';
import {
  INDEX,
} from '@/utils/tableColumn';
import {toF9, setHrefUrlTool, toBondDetail} from '@/utils';

export function useTable() {
  const columns = ref<IColumnsOption[]>([
    {...INDEX},
    {
      field: 'bondShortName',
      title: '债券简称',
      width: 270,
      fixed: 'left',
      headerAlign: 'center',
      sortBy: 'bondShortName',
      slots: {
        default: ({row}) => {
          const content = row.highlight?.bondShortName ? row.highlight?.bondShortName : row.bondShortName;
          return <div>
            <a title={row.bondShortName} class="companyName"
               onClick={() => toBondDetail(row.id)}
               v-html={content}>

            </a>
            {row.expired ? <span class="bondTypeLabel"
                                 style={'color:#fff;background:#fb9196'}>已过期 </span> : ''}
          </div>;
        }
      }

    },
    {
      field: 'securitiesCode',
      title: '债券代码',
      align: 'center',
      // sortable: true,
      width: 110,
      sortBy: 'securitiesCode'
    },
    {
      field: 'certificationDate',
      title: '认证日期',
      align: 'center',
      // sortable: true,
      width: 110,
      sortBy: 'certificationDate'
    },
    {
      field: 'certificationResult',
      title: '认证结果',
      align: 'center',
      // sortable: true,
      width: 110,
      sortBy: 'certificationResult'
    },
    {
      field: 'certificationResultsDescription',
      title: '认证结果描述',
      align: 'center',
      // sortable: true,
      width: 250,
      sortBy: 'certificationResultsDescription',
      showOverflow: 'title'
    },
    {
      field: 'issuingScale',
      title: '发行规模',
      align: 'center',
      // sortable: true,
      sortBy: 'issuingScale',
      width: 110,
      formatter: ({row}) => {
        return row.issuingScale ? row.issuingScale + '亿' : '-';
      }
    },
    {
      field: 'couponRateDisplay',
      title: '票面利率',
      align: 'center',
      // sortable: true,
      sortBy: 'couponRateDisplay',
      width: 180,
      formatter: ({row}) => {
        return row.couponRateDisplay ? row.couponRateDisplay + '%' : '-';
      }
    },
    {
      field: 'issuingDate',
      title: '发行起始日',
      align: 'center',
      // sortable: true,
      width: 110,
      sortBy: 'issuingDate'
    },
    {
      field: 'companyName',
      title: '发行人',
      width: 260,
      headerAlign: 'center',
      sortBy: 'companyName',
      slots: {
        default: ({row}) => {
          const content = row.highlight?.companyName ? row.highlight?.companyName : row.companyName;
          if (row.companyId) {
            return <a title={row.companyName} class="companyName"
                      onClick={() => toF9(row.companyId)}
                      v-html={content}></a>;
          } else {
            return <span title={row.companyName || ''} v-html={content || '-'}></span>;
          }
        }
      }
    },
  ]);

  return {
    columns,
  };
}
